<template>
  <div class="alluser">
    <el-card shadow="never" class="homeTop">

      <el-row>
        <el-col :span="10">
           <el-input v-model="myParams.keyword" placeholder="请输入内容" @keyup.enter.native="clickSearch" clearable></el-input>
        </el-col>
        <el-col :span="2">
          <el-button type="primary" plain icon="el-icon-search" style="width:100%" @click="clickSearch">搜索</el-button>
        </el-col>
      </el-row>

    </el-card>
    <el-card shadow="never" class="userAllMain">
      <el-table
          stripe
          border
          height="470px"
          :data="userData"
          style="width: 100%">
          <el-table-column
            type="index"
            label="编号"
            width="50">
          </el-table-column>

          <el-table-column
            prop="nickname"
            label="姓名"
            width="100">
          </el-table-column>

          <el-table-column
            label="日期"
            width="180">
            <template slot-scope="scope">
              <i class="el-icon-time" style="font-size:12px"></i>
              <span style="margin-left: 5px; font-size:12px; color:#666">{{ myDate(scope.row.posttime) }}</span>
            </template>
          </el-table-column>

          <el-table-column
            prop="contact"
            label="电话"
            width="150">
          </el-table-column>

          <el-table-column
            prop="weixin"
            label="微信"
            width="150"
            >
          </el-table-column>

          <el-table-column
            prop="qq"
            label="QQ"
            width="100">
          </el-table-column>

          <el-table-column
            label="专业">
            <template slot-scope="scope">
              <div class="className">{{scope.row.infoclass}}</div>
              <span>{{ scope.row.zhuanye }}</span>
            </template>
          </el-table-column>

          <el-table-column
            prop="laiyuan"
            label="信息来源"
            >
          </el-table-column>

          <el-table-column
            prop="dizhi"
            label="所在地区"
            width="100">
          </el-table-column>

          <el-table-column
            prop="kefu"
            label="客服"
            width="100">
          </el-table-column>

          <el-table-column
            label="操作"
            width="120">
            <template slot-scope="scope">
              <el-tooltip effect="dark" content="修改" placement="top">
              <el-button type="primary" icon="el-icon-edit" size="small" @click="clickUpdata(scope.row.id)"></el-button>
              </el-tooltip>

              <el-tooltip effect="dark" content="删除" placement="top">
              <el-button type="danger" icon="el-icon-delete" size="small" @click="clickDel(scope.row.id)"></el-button>
              </el-tooltip>
            </template>
          </el-table-column>
      </el-table>
    </el-card>

    <el-card shadow="never" class="pages">
       <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :page-sizes="[7, 10, 20]"
        :page-size="10"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total">
      </el-pagination>
    </el-card>

    <updata-dialog ref="updataDialog"></updata-dialog>
  </div>
</template>

<script>
import { userAllFun, delUserRow } from '@/nextwork/nextworks'
import { myDate } from '@/assets/js/common'
import updataDialog from './children/updataDialog.vue'
export default {
  data () {
    return {
      myParams: {
        num: 7,
        page: 1,
        keyword: ''
      },
      userData: [],
      total: 0
    }
  },
  components: {
    updataDialog
  },
  mounted () {
    this.getAllData()
    const userRes = window.sessionStorage.getItem('userRes')
    if (userRes) {
      window.sessionStorage.removeItem('userRes')
    }
  },
  methods: {
    // 搜索
    clickSearch () {
      this.getAllData()
    },
    // 修改
    clickUpdata (id) {
      this.$refs.updataDialog.rowId = id
      this.$refs.updataDialog.ShowDialog = true
    },
    // 删除一个用户
    clickDel (id) {
      this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'error'
      }).then(res => {
        delUserRow(id).then(res => {
          this.getAllData()
          this.$message.success('删除成功')
        })
      }).catch(err => {
        if (err) {
          this.$message.error('您取消了删除')
        }
      })
    },
    // 时间戳
    myDate (time) {
      return myDate(time, 1)
    },
    getAllData () {
      userAllFun(this.myParams).then(res => {
        this.userData = res.data.results
        this.total = res.data.num
      })
    },
    // 条数改变时触发
    handleSizeChange (e) {
      this.myParams.num = e
      this.getAllData()
    },
    // 切换页码时触发
    handleCurrentChange (e) {
      this.myParams.page = e
      this.getAllData()
    }
  }
}
</script>

<style lang="less" scoped>
.alluser{
  width: 100%;
  margin: 24px;
  .userAllMain{
    margin-top: 20px;
  }
}
.className{
  position: absolute;
  right: 0;
  top: 0;
  font-size: 12px;
  transform: scale(0.9);
  color: #67C23A;
}
.pages{
  margin-top: 10px;
  text-align: center;
}
</style>
